package 单周赛.history;

import java.util.HashSet;
import java.util.Set;

/**
 *
 */
public class 第315场单周赛 {

    public static void main(String[] args) {

        System.out.println(countDistinctIntegers(new int[]{1, 13, 10, 12, 31}));

        System.out.println(sumOfNumberAndReverse(63));

    }

    public int findMaxK(int[] nums) {
        int k = -1;
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (set.contains(-num)) {
                k = Math.max(k, Math.abs(num));
            }
            set.add(num);
        }

        return k;
    }

    public static int countDistinctIntegers(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
            set.add(reverseNum(num));
        }

        return set.size();
    }

    public static boolean sumOfNumberAndReverse(int num) {
        for (int i = num; i >= 0; i--) {
            if (reverseNum(num) + i == num) {
                return true;
            }
        }
        return false;
    }

    private static int reverseNum(int num) {
        int rev = 0;
        while (num > 0) {
            rev = rev * 10 + num % 10;
            num /= 10;
        }
        return rev;
    }

}
